package com.rk.cust.application.api.assembler;

import com.rk.cust.application.api.request.AddCustRequestDto;
import com.rk.cust.application.api.request.ModifyCustRequestDto;
import com.rk.cust.application.api.response.CustResponseDto;
import com.rk.cust.common.util.TimeFormatUtil;
import com.rk.cust.domain.entity.Cust;
import com.rk.cust.domain.vo.CertType;
import com.rk.cust.domain.vo.CustStatus;
import org.springframework.stereotype.Component;

@Component
public class CustDtoAssembler {

    public CustResponseDto assembler(Cust cust){
        CustResponseDto custResponseDto = new CustResponseDto();
        if (null == cust){
            return custResponseDto;
        }else {
            custResponseDto.setId(String.valueOf(cust.getId()));
            custResponseDto.setCorporation(cust.getCorporation());
            custResponseDto.setCertType(cust.getCertType().name());
            custResponseDto.setCertNo(cust.getCertNo());
            custResponseDto.setStatus(cust.getStatus().name());
            custResponseDto.setCreateTime(TimeFormatUtil.format(cust.getCreateTime()));
            return custResponseDto;
        }
    }

    public Cust assembler(AddCustRequestDto addCustRequestDto) {
        Cust cust = new Cust();
        if (null == addCustRequestDto){
            return cust;
        }else {
            cust.setCorporation(addCustRequestDto.getCorporation());
            cust.setCertType(CertType.valueOf(addCustRequestDto.getCertType()));
            cust.setCertNo(addCustRequestDto.getCertNo());
            cust.setStatus(CustStatus.unactivated);
            return cust;
        }
    }

    public Cust assembler(ModifyCustRequestDto modifyCustRequestDto) {
        Cust cust = new Cust();
        if (null == modifyCustRequestDto){
            return cust;
        }else {
            cust.setCorporation(modifyCustRequestDto.getCorporation());
            cust.setCertType(CertType.valueOf(modifyCustRequestDto.getCertType()));
            cust.setCertNo(modifyCustRequestDto.getCertNo());
            return cust;
        }
    }
}
